import request from "../../../../request/request"
Page({
  data: {
    // 接收到的id
    id: "001",
    // 接收到的 name
    name:"",
    // 千分制操作记录
    frationList: [
      { id: "001", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "001001", reason: "好人好事", isAdd: true, reward: "10", date: "2021.6.8" },
      { id: "002", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "003", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "004", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "004001", reason: "好人好事", isAdd: true, reward: "15", date: "2021.6.8" },
      { id: "005", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "006", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "007", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "007001", reason: "好人好事", isAdd: true, reward: "15", date: "2021.6.8" },
      { id: "008", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "009", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "010", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "011", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "012", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "012001", reason: "好人好事", isAdd: true, reward: "15", date: "2021.6.8" },
      { id: "013", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "014", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
      { id: "014001", reason: "好人好事", isAdd: true, reward: "15", date: "2021.6.8" },
      { id: "015", reason: "迟到/早退", isAdd: false, reward: "15", date: "2021.6.8" },
    ],
    // 奖励合计
    reward: 0,
    // 扣除总分
    reduce: 0,
    // 剩余总分
    surplus: 1000
  },
  onLoad: function (options) {
    this.setData({ id: options.id,name:options.name })
    this.countSum()
    console.log(options)
    this.queryFtactionById()
  },
  // 根据学生id查询千分制
  queryFtactionById(){
    // request({url:`tms_inquery/${this.data.id}`}).then(res => {
    //   this.setData({
    //     frationList
    //   })
    // })
    console.log(this.data.id)
  },
  // 计算分数
  countSum() {
    this.data.frationList.forEach((item) => {
      if (item.isAdd) {
        this.setData({
          reward: this.data.reward += Number(item.reward),
          surplus: this.data.surplus + Number(item.reward)
        })
      } else {
        this.setData({
          reduce: this.data.reduce -= Number(item.reward),
          surplus: this.data.surplus - Number(item.reward)
        })
      }
    })
  }

})